package com.huluobo.a2107mvpimdemo.addFriend.view;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huluobo.a2107mvpimdemo.R;
import com.huluobo.a2107mvpimdemo.addFriend.presenter.AddFriendContract;
import com.huluobo.a2107mvpimdemo.addFriend.presenter.AddFriendPresenter;
import com.huluobo.a2107mvpimdemo.base.BaseActivity;

public class AddFriendActivity extends BaseActivity<AddFriendContract.View, AddFriendPresenter> implements AddFriendContract.View {
    private ImageView back;
    private EditText username, reason;
    private Button toAddBtn;
    private TextView title;

    @Override
    public void onAddSuccess() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(AddFriendActivity.this, "添加好友成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onAddFailed(String error) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(AddFriendActivity.this, "添加好友失败:" + error, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void initData() {
        presenter = new AddFriendPresenter();
    }

    @Override
    protected void initView() {
        title = findViewById(R.id.header_title);
        title.setText("添加好友");
        username = findViewById(R.id.addFriend_username);
        reason = findViewById(R.id.addFriend_reason);
        toAddBtn = findViewById(R.id.addFriend_btn);

        back = findViewById(R.id.header_back);
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        toAddBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.add(username.getText().toString(), reason.getText().toString());
            }
        });
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_add_friend;
    }
}